#ifndef __DATABASE_H
#define __DATABASE_H

/*
This class contains all functions that interact directly with the database or sqlite.
Notice: this class is a singleton, and can be accessed wherever.

The functions are broken into three different categories:
	initialization - functions used to create the database
	general utility - functions used no matter what aspect of war is being used
				also functions that are used by other functions inside Database
	soldier functions - functions used by soldiers

Functions
	
	addSoldier	- add a soldier to the database and return that soldier's id
	addArmy		- add army to the database
	
	s_getAttribute	- get a soldier's attribute

	s_getTarget	- get a soldier's current target
	s_setTarget	- set the soldier's current target
	s_newTarget	- find a random target for the soldier

	s_getHealth	- get soldier's current health
	s_setHealth	- set soldier's current health
*/

#include "sqlite3.h"
#include <iostream>
#include <sstream>

static int cb_query(void* value, int argc, char** argv, char** colName);

class Database
{
public:
	// initialization
	static Database* getSinglePtr();
	void initialize(std::string filename);
	~Database();

protected:
	Database();

	// general utility functions
	void addArmy(std::string name);
	int addSoldier(std::string army, int health);

	// soldier functions
	char** s_getAttributes(int soldier, std::string attrs);

	int s_getTarget(int soldier);
	int s_setTarget(int soldier, int target);
	int s_newTarget(int soldier);	// note: set new target attribute as well

	int s_getHealth(int soldier);
	int s_setHealth(int soldier, int health);

private:
	static Database* pInstance;
	// direct database access
	sqlite3* db;
	bool db_init(std::string name);
	bool db_exec(std::string command, int (*cb)(void*, int, char**, char**) = NULL);
	bool db_close();
};

#endif